package com.starsoft.frame.base.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.starsoft.frame.base.bean.BaseAcount;
import com.starsoft.frame.base.bean.BaseUser;
import com.starsoft.frame.base.dao.AcountDao;
import com.starsoft.frame.core.orm.PageObject;
import com.starsoft.frame.core.service.BaseService;

@Service
public class AcountService extends BaseService{

	@Autowired
	AcountDao acountDao;
	
	public BaseAcount getAcount(Integer acountId){
		return acountDao.get(acountId);
	}
	
	public List<BaseAcount> getAcount(BaseUser user){
		return acountDao.getAcount(user);
	}
	
	public List<BaseAcount> getSunAcount(BaseAcount acount){
		return acountDao.getSunAcounts(acount);
	}
	
	public List<BaseAcount> getParentAcount(Integer userId){
		return acountDao.getParentAcount(userId);
	}
	
	public Map<String, Object> pageParentAcount(BaseUser user, PageObject po) {
		return acountDao.pageParentAcount(user, po);
	}
	
	public void deleteAcount(BaseAcount acount){
		acountDao.delete(acount);
	}
	
	public void saveAcount(BaseAcount acount){
		acountDao.saveOrUpdate(acount);
	}
	
	public void checkCanRemove(BaseAcount acount) {
		if (!getSunAcount(acount).isEmpty()) {
			throw new RuntimeException("为父账户，不能移除");
		}
	}
	
}
